package com.nageoffer.shortlink.project.config;

import com.nageoffer.shortlink.common.constant.RedisConstant;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class ShortLinkStatsStreamInitializeTask implements InitializingBean {
    private final StringRedisTemplate stringRedisTemplate;

    @Override
    public void afterPropertiesSet() throws Exception {
        Boolean hasKey = stringRedisTemplate.hasKey(RedisConstant.SHORT_LINK_STATS_STREAM_TOPIC_KEY);
        if (hasKey==null || !hasKey) {
            stringRedisTemplate.opsForStream().createGroup(RedisConstant.SHORT_LINK_STATS_STREAM_TOPIC_KEY,RedisConstant.SHORT_LINK_STATS_STREAM_GROUP_KEY);
        }
    }
}
